package demo_0711;

import java.util.Scanner;

public class T13_0324 {
   static class TreeNode {
        char val;
        TreeNode left;
        TreeNode right;
        TreeNode() {}
        TreeNode(char val) { this.val = val; }
        TreeNode(char val, TreeNode left, TreeNode right) {
            this.val = val;
            this.left = left;
            this.right = right;
        }
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextLine()) { // 注意 while 处理多个 case
            String s = in.nextLine();
            TreeNode root = creat(s);
            inOredr(root);
        }
    }
    static int i = 0;
    private static TreeNode creat(String s) {
         TreeNode root = null;
        if (s.charAt(i) != '#') {
            root = new TreeNode(s.charAt(i));
            i++;
            root.left = creat(s);
            root.right = creat(s);
        } else {
            i++;
        }
        return root;
    }
    private static void inOredr(TreeNode root) {
       if (root == null) return;
       inOredr(root.left);
       System.out.print(root.val + " ");
       inOredr(root.right);
    }
}
